package iit.projects.etaxi.util;

//import org.icefaces.application.showcase.view.bean.NavigationNames;

import javax.faces.model.SelectItem;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.io.Serializable;

@SuppressWarnings("serial")
public class StyleBean implements Serializable {

    // possible theme choices
    private final String RIME = "rime";
    private final String XP = "xp";
    private final String ROYALE = "royale";

    // default theme
    private String currentStyle = RIME;
    @SuppressWarnings("unused")
    private String tempStyle = RIME;

    // available style list
    private ArrayList<SelectItem> styleList;

    private HashMap<String, StylePath> styleMap;

    /**
     * Creates a new instance of the StyleBean.
     */
    public StyleBean() {
        // initialize the style list
        styleList = new ArrayList<SelectItem>();
        styleList.add(new SelectItem(RIME, RIME));
        styleList.add(new SelectItem(XP, XP));
        styleList.add(new SelectItem(ROYALE, ROYALE));

        styleMap = new HashMap<String, StylePath>(3);
        styleMap.put(RIME, new StylePath(
                "./xmlhttp/css/rime/rime.css",
                "./xmlhttp/css/rime/css-images/"));
        styleMap.put(XP, new StylePath(
                "./xmlhttp/css/xp/xp.css",
                "./xmlhttp/css/xp/css-images/"));
        styleMap.put(ROYALE, new StylePath(
                "./xmlhttp/css/royale/royale.css",
                "./xmlhttp/css/royale/css-images/"));
    }

    /**
     * Gets the current style.
     *
     * @return current style
     */
    public String getCurrentStyle() {
        return currentStyle;
    }

    /**
     * Sets the current style of the application to one of the predetermined
     * themes.
     *
     * @param currentStyle name of new style
     */
    public void setCurrentStyle(String currentStyle) {
        this.tempStyle = currentStyle;
    }

    /**
     * Gets the html needed to insert a valid css link tag.
     *
     * @return the tag information needed for a valid css link tag
     */
    public String getStyle() {
        return "<link rel=\"stylesheet\" type=\"text/css\" href=\"" +
                ((StylePath)styleMap.get(currentStyle)).getCssPath() + "\"></link>";
    }

    /**
     * Gets the image directory to use for the selectinputdate and tree
     * theming.
     *
     * @return image directory used for theming
     */
    public String getImageDirectory() {
        return ((StylePath)styleMap.get(currentStyle)).imageDirPath;
    }

    /**
     * Applies temp style to to the current style and image directory and
     * manually refreshes the icons in the navigation tree. The page will reload
     * based on navigation rules to ensure the theme is applied; this is
     * necessary because of difficulties encountered by updating the stylesheet
     * reference within the <HEAD> of the document.
     *
     * @return the reload navigation attribute
     */
//    public String changeStyle() {
//        if (!currentStyle.equalsIgnoreCase(tempStyle)) {
//            currentStyle = tempStyle;
//            return NavigationNames.THEME_CHANGE;
//        }
//        return null;
//    }

    /**
     * Gets a list of available theme names that can be applied.
     *
     * @return available theme list
     */
    public List<SelectItem> getStyleList() {
        return styleList;
    }

    /**
     * Utility class to manage different cssPath and imageDir namd
     */
    public class StylePath implements Serializable{

		private String cssPath;
        private String imageDirPath;

        public StylePath(String cssPath, String imageDirPath) {
            this.cssPath = cssPath;
            this.imageDirPath = imageDirPath;
        }

        public String getCssPath() {
            return cssPath;
        }

        public String getImageDirPath() {
            return imageDirPath;
        }
    }

}
